package com.jintian.smart.kernel.message.mapper;

import com.jintian.smart.base.api.message.entity.NoticeEntity;
import com.jintian.smart.base.api.message.form.NoticeEmployeeQueryForm;
import com.jintian.smart.base.api.message.form.NoticeQueryForm;
import com.jintian.smart.base.api.message.form.NoticeViewRecordQueryForm;
import com.jintian.smart.base.api.message.form.NoticeVisibleRangeForm;
import com.jintian.smart.base.api.message.vo.NoticeEmployeeVO;
import com.jintian.smart.base.api.message.vo.NoticeVO;
import com.jintian.smart.base.api.message.vo.NoticeViewRecordVO;
import com.jintian.smart.base.api.message.vo.NoticeVisibleRangeVO;
import com.jintian.smart.kernel.orm.mapper.IBaseExtMapper;
import org.beetl.sql.core.page.PageResult;
import org.beetl.sql.mapper.annotation.Mapper;
import org.beetl.sql.mapper.annotation.Param;
import org.beetl.sql.mapper.annotation.SqlResource;
import org.beetl.sql.mapper.annotation.Update;

import java.util.List;

/**
 * 公告、通知、新闻等等
 */
@Mapper
@SqlResource("msg.Notice")
public interface NoticeMapper extends IBaseExtMapper<NoticeEntity> {
    // ================================= 数据范围相关 【子表】 =================================

    /**
     * 保存可见范围
     */
    void insertVisibleRange(@Param("noticeId") Long noticeId, @Param("visibleRangeFormList") List<NoticeVisibleRangeForm> visibleRangeFormList);

    /**
     * 删除可见范围
     */
    void deleteVisibleRange(@Param("noticeId") Long noticeId);

    /**
     * 相关可见范围
     */
    List<NoticeVisibleRangeVO> queryVisibleRange(@Param("noticeId") Long noticeId);

    // ================================= 通知公告【主表】 相关  =================================

    /**
     * 后管分页查询资讯
     */
    PageResult<NoticeVO> query(NoticeQueryForm queryForm);


    /**
     * 更新删除状态
     */
    void updateDeletedFlag(@Param("noticeId") Long noticeId);

    // ================================= 通知公告【员工查看】 相关  =================================

    /**
     * 查询 员工 查看到的通知公告
     */
    PageResult<NoticeEmployeeVO> queryEmployeeNotice(@Param("requestEmployeeId") Long requestEmployeeId,
                                                     @Param("query") NoticeEmployeeQueryForm noticeEmployeeQueryForm,
                                                     @Param("requestEmployeeDepartmentIdList") List<Long> requestEmployeeDepartmentIdList,
                                                     @Param("deletedFlag") Integer deletedFlag,
                                                     @Param("administratorFlag") Integer administratorFlag,
                                                     @Param("departmentDataType") Integer departmentDataType,
                                                     @Param("employeeDataType") Integer employeeDataType

    );

    /**
     * 查询 员工 未读的通知公告
     */
    PageResult<NoticeEmployeeVO> queryEmployeeNotViewNotice(@Param("requestEmployeeId") Long requestEmployeeId,
                                                            @Param("query") NoticeEmployeeQueryForm noticeEmployeeQueryForm,
                                                            @Param("requestEmployeeDepartmentIdList") List<Long> requestEmployeeDepartmentIdList,
                                                            @Param("deletedFlag") Integer deletedFlag,
                                                            @Param("administratorFlag") Integer administratorFlag,
                                                            @Param("departmentDataType") Integer departmentDataType,
                                                            @Param("employeeDataType") Integer employeeDataType

    );

    long viewRecordCount(@Param("noticeId") Long noticeId, @Param("employeeId") Long employeeId);

    /**
     * 查询通知、公告的 查看记录
     */
    PageResult<NoticeViewRecordVO> queryNoticeViewRecordList(@Param("queryForm") NoticeViewRecordQueryForm noticeViewRecordQueryForm);

    /**
     * 保存查看记录
     */
//    @Update
//    void insertViewRecord(@Param("noticeId") Long noticeId, @Param("employeeId") Long employeeId, @Param("ip") String ip, @Param("userAgent") String userAgent, @Param("pageViewCount") Integer pageViewCount);

    /**
     * 更新查看记录
     */
    @Update
    void updateViewRecord(@Param("noticeId") Long noticeId, @Param("employeeId") Long requestEmployeeId, @Param("ip") String ip, @Param("userAgent") String userAgent);

    /**
     * 更新 浏览量
     *
     * @param noticeId               通知 id
     * @param pageViewCountIncrement 页面浏览量的增量
     * @param userViewCountIncrement 用户浏览量的增量
     */
    @Update
    void updateViewCount(@Param("noticeId") Long noticeId, @Param("pageViewCountIncrement") Integer pageViewCountIncrement, @Param("userViewCountIncrement") Integer userViewCountIncrement);
}
